Registry Mirror
Skip to content

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

More stuff similar to the last PR but in other areas.

Tests and fixes are split apart, so I would recommend just looking at the fix commits, which are all isolated. That split makes the PR look bigger than it is.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved escaping and name-handling defects can produce invalid code or JSON, break JSDoc comments, and alter or leave stale renamed references.

9 open issues
What changed in this PR

This PR hardens escaping in TypeScript’s language service so generated edits preserve unusual names and string contents across renames, completions, imports, and code fixes. It also updates compiler alias selection for non-identifier export names.

Changes:

  • Adds context-aware escaping for strings, snippets, JSDoc text, and file-rename edits.
  • Improves handling of quoted names, mapped properties, destructuring, and Unicode JSX auto-imports.
  • Adds regression tests and updates rename baselines to use an identifier placeholder.
File Description
tsc/​testdata/​tests/​cases/​compiler/​declarationEmitNonIdentifierExportName.ts Tests quoted exports and identifier alias fallback.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​renameInCommonFile.baseline Updates logged rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​renameAncestorProjectRefMangement.baseline Updates project-reference rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMapsNotSolutionEditEnd.baseline Updates rename placeholder after end edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMapsNotSolutionEdit.baseline Updates rename placeholder after edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMapsNotSolution.baseline Updates source-map rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMapsEditEnd.baseline Updates rename placeholder after end edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMapsEdit.baseline Updates rename placeholder after edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithSourceMaps.baseline Updates source-map rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithProjectReferencesEditEnd.baseline Updates project-reference rename placeholder after end edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithProjectReferencesEdit.baseline Updates project-reference rename placeholder after edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithProjectReferences.baseline Updates project-reference rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEditEnd.baseline Updates redirect-disabled rename placeholder after end edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithDisableSourceOfProjectReferenceRedirectEdit.baseline Updates redirect-disabled rename placeholder after edits.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameWithDisableSourceOfProjectReferenceRedirect.baseline Updates redirect-disabled rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameTargetDoesNotExist.baseline Updates missing-target rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRenameStartingAtDefinition.baseline Updates definition-origin rename placeholder.
tsc/​testdata/​baselines/​reference/​fourslash/​state/​declarationMapsRename.baseline Updates declaration-map rename placeholder.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitNonIdentifierExportName.types Records inferred alias types.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitNonIdentifierExportName.symbols Records quoted export symbols.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitNonIdentifierExportName.js Records JavaScript and declaration output.
tsc/​testdata/​baselines/​reference/​compiler/​declarationEmitNonIdentifierExportName.errors.txt Records the unnameable-export diagnostic.
tsc/​internal/​ls/​utilities.go Escapes line separators in generated quoted strings.
tsc/​internal/​ls/​rename.go Adds string escaping and non-identifier alias handling.
tsc/​internal/​ls/​organizeimports.go Quotes import-attribute grouping keys to avoid collisions.
tsc/​internal/​ls/​lsutil/​utilities.go Adds comment-safe string escaping.
tsc/​internal/​ls/​file_rename.go Escapes replacement paths and guards reference directives.
tsc/​internal/​ls/​completions.go Separates snippet escaping and guards generated JSDoc text.
tsc/​internal/​ls/​codeactions_missingmemberfixer.go Quotes non-identifier mapped member names.
tsc/​internal/​ls/​codeactions_fixmissingtypeannotation.go Uses element access for non-identifier binding properties.
tsc/​internal/​ls/​autoimport/​view.go Decodes Unicode initials for JSX completion filtering.
tsc/​internal/​ls/​autoimport/​fix.go Escapes JSDoc imports and preserves quoted import names.
tsc/​internal/​fourslash/​tests/​renameEscaping_test.go Adds literal and non-identifier rename cases.
tsc/​internal/​fourslash/​tests/​organizeImportsAttributes4_test.go Tests quoted import-attribute values.
tsc/​internal/​fourslash/​tests/​importStatementCompletions_noSnippet_test.go Tests plain-text imports containing dollar signs.
tsc/​internal/​fourslash/​tests/​getEditsForFileRename_escapedSpecifier_test.go Tests escaped paths and JSDoc file-renaming edits.
tsc/​internal/​fourslash/​tests/​completionsSnippetEscaping_test.go Tests snippet and plain-text completion escaping.
tsc/​internal/​fourslash/​tests/​completionsOverridingMethod22_test.go Updates plain-text dollar-sign completion output.
tsc/​internal/​fourslash/​tests/​completionsImport_jsxOpeningTagImportDefault_test.go Adds a non-ASCII JSX default-import case.
tsc/​internal/​fourslash/​tests/​completionFilterText3_test.go Tests line-separator property completion escaping.
tsc/​internal/​fourslash/​tests/​codeFixPromoteTypeOnlyOrderingCrash_test.go Tests promotion of quoted type-only imports.
tsc/​internal/​fourslash/​tests/​codeFixMissingTypeAnnotationOnExports14_test.go Tests extraction of non-identifier binding properties.
tsc/​internal/​fourslash/​tests/​codeFixClassImplementInterfaceMappedType2_test.go Tests quoted mapped member generation.
tsc/​internal/​fourslash/​tests/​basicJSDocCompletions_test.go Tests comment terminators in parameter completions.
tsc/​internal/​fourslash/​tests/​autoImportQuotedModuleSpecifier_test.go Tests comment-safe JSDoc auto-import paths.
tsc/​internal/​fourslash/​tests/​autoCloseTag_test.go Tests escaped JSX closing-tag output.
tsc/​internal/​fourslash/​fourslash.go Uses an identifier placeholder for rename baselines.
tsc/​internal/​checker/​symbolaccessibility.go Filters non-identifier aliases for import-type qualifiers.

Review effort: Max

Comment thread tsc/internal/ls/autoimport/view.go Resolved
Comment thread tsc/internal/ls/completions.go Resolved
Comment thread tsc/internal/ls/file_rename.go Resolved
Comment thread tsc/internal/ls/file_rename.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tsc/internal/ls/rename.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tsc/internal/checker/nodebuilderimpl.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tsc/internal/ls/rename.go Resolved
Comment thread tsc/internal/ls/rename.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tsc/internal/checker/nodebuilderimpl.go Resolved
@jakebailey

Copy link
Copy Markdown
Member Author

Opened #65744

@DanielRosenwasser

Copy link
Copy Markdown
Member

"Escaping" == "qualifying"/"rewriting"?

@jakebailey

Copy link
Copy Markdown
Member Author

Sort of, it's more about "some text makes it into the user code via a completion or code action"

Auto-import should skip or capitalize an export name for a JSX tag
only when JSX would read that name as an intrinsic element. Checking
the first byte for an uppercase letter misread multi-byte characters:
a name starting with a CJK character has a first byte that reads as a
lowercase letter, so the component was never offered, and capitalizing
the first byte of a multi-byte character produced invalid UTF-8 that
crashed when resolving the completion.
Completions that quote a name, such as element access completions for
non-identifier properties, built the string literal from JSON escapes.
JSON leaves U+2028 and U+2029 raw, but the characters are invisible in
source and end a string literal in engines before ES2019, which emit
can target.

Quote completion text with the escaping shared by other edits, which
escapes these characters and comment terminators. It writes lone
surrogates with uppercase hex digits, matching the text that JSX
attribute completions insert.
When a rename adds an alias to keep a local name, the new name lands in
an export name or property name slot. A new name that is not an
identifier, such as `a-b`, produced `export { foo as a-b }` and
`const { a-b: x } = o`, which do not parse. These slots accept string
literals, so quote the new name there.

An `import { foo }` cannot bind a non-identifier local at all, so it
becomes `import { "a-b" as foo }` and uses of the local `foo` keep
their name.
Config files are JSON, and JavaScript string escapes such as \v or
\x00 are invalid there. Renaming a file to a name with such a character
wrote a tsconfig.json that no longer parses.
A file renamed to a name with a quote left every reference directive
delimited by that quote pointing at the old path. When the path does
not contain the other quote character, it can still be written by
switching the directive to that quote.
Property names in nested destructuring patterns are copied into the
generated @PARAM tags the same way as top-level ones, so a name
containing */ or a line break ends the comment or the tag early.
Renaming a numeric property such as 0 in { 0: x } wrote the new name
unquoted, so a name that is not an identifier produced invalid code.
Element accesses of the property were already quoted. A new name that
is itself a non-negative number stays unquoted so the property keeps
its numeric key.
In export { "a b" } from "m", the rename edit covers only the
contents of the string literal. Adding an alias clause there put the
whole clause inside one literal, so each name has to be written as its
own literal within that range.
JSX attribute strings are taken literally, so a renamed string literal
reference inside one has to be written as raw text. When the attribute's
quote cannot contain the new name, the other quote or an expression
container replaces the whole initializer; otherwise the edit stays
inside the quotes, which keeps it applicable in content-mapped files
where only the value lies in a verbatim span.
The name in `export * as ns` is a module export name that may be a
string literal, so renaming it to a non-identifier quotes the name in
the same way as an export specifier.
A property synthesized by intersecting mapped types has no declaration
to copy its name from, so its name was written as an identifier even
when it was not one, which crashed the printer.
Clients compare the filter text against the import statement typed so
far, which contains neither tab stops nor snippet escapes. Building the
filter text from the plain statement keeps names and module specifiers
containing `$` or `\` matchable.
A type reachable only through an export with a string literal name,
such as `export { A as "a b" }`, was printed as `import("./dep").a b`,
which does not parse. Declaration emit wrote it out as is, and code
fixes inserted it into user files.

Import type qualifiers must be identifiers, so these exports cannot be
used to name the type. When the module has another export of the same
type with an identifier name, that name is used; otherwise the type is
not nameable from outside the module, and declaration emit reports the
usual error.
Import type qualifiers must be identifiers, so a module exporting a
type only under a string literal name cannot be used to name it. The
container index used to find re-exporting modules included such
modules, and one could be chosen over a module with a usable name.
A qualified type name such as `dep.x` can only reference an export with
an identifier name, so exports like `export { A as "a b" }` cannot name
a type through a namespace import. Choosing one emits a declaration file
that does not parse instead of falling back to another export or
reporting that the type cannot be named. Values stay reachable through
element access, as in `ns["a b"]`, so type queries for them are written
as indexed access types, as in `(typeof ns)["a b"]`. Static members with
such names are written the same way, including through import types, as
in `typeof import("./dep").C["a b"]`.
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Dec 4, 2026
@DanielRosenwasser

Copy link
Copy Markdown
Member

Cherry pick this if you feel like it's good to go. I don't want to kick it off prematurely.

@jakebailey

Copy link
Copy Markdown
Member Author

Pulled out #65789 and #65790 which were found during this but are not exactly the kind of bug in this PR.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Dec 4, 2026
Merged via the queue into microsoft:main with commit 3f85ce2 Dec 4, 2026
34 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the fix-ls-edit-escaping branch December 4, 2026 17:42
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Dec 4, 2026
@jakebailey

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) cherry-pick this to release-7.1

@typescript-automation

typescript-automation Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick this to release-7.1 ✅ Started ✅ Results

@typescript-automation

Copy link
Copy Markdown
Contributor

Hey, Jake Bailey (@jakebailey)! I've created #65792 for you.

Jake Bailey (jakebailey) added a commit that referenced this pull request Dec 4, 2026
…#65792)

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants